#include "mainmanager.h"
#include "PluginInterfaces.h"
#include "../helloword/hellowordservice.h"
#include "ctkPluginContext.h"
#include "ctkPluginFrameworkLauncher.h"


void MainManager::declareQML()
{
    qmlRegisterType<MainManager>("MainManager", 1, 0, "MainManager");
}

void MainManager::doTestPostMessage(const QString data)
{
    postCtkEvent(MAINWINDOW_STRING, data);
}

QString MainManager::doGetSTringFromHelloword()
{
    QString getString = QString();
    ctkPluginContext *context = ctkPluginFrameworkLauncher::getPluginContext();
    ctkServiceReference ref = context->getServiceReference<HelloWordService>();
    if (ref) {
        HelloWordService* service = context->getService<HelloWordService>(ref);
        if (service != nullptr) {
            getString = service->doGetSTringFromHelloword();
            qInfo() << QString("MainManager doGetSTringFromHelloword %1.").arg(getString);
            context->ungetService(ref);
        }
    } else {
        qFatal("MainManager doGetSTringFromHelloword failed.");
    }

    return getString;
}
